import pytest
from config import *
from devices import app_cold_start


@pytest.fixture(scope='function', autouse=True)
# autouse=True这将使该 fixture 在每个测试用例中自动执行，而无需显式地添加装饰器或参数
def cl(request):
    print('开始')
    # print(f'用例信息{request}')
    path = request.node.fspath
    # print(f"Current test case: {node.name}")
    # print(f"Test file path: {node.fspath}")
    # print(f"Test class: {node.getparent}")
    if path == test_accountcenter_path:
        package_name = test_accountcenter_package_name
    elif path == test_familytime_path:
        package_name = test_familytime_package_name
    else:
        package_name = ''
    app_cold_start(package_name)
    yield
    print('结束')

# def pytest_runtest_protocol(item, nextitem):
#     reports = yield
#     for report in reports:
#         if report.when == "call" and report.failed:
#             # 检查是否是 UiObjectNotFoundError 异常
#             if isinstance(report.longrepr, UiObjectNotFoundError):
#                 # 获取异常信息
#                 err_info = str(report.longrepr)
#
#                 # 调用截图方法
#                 capture_screenshot(err_info)
